home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2006 April / DPPRO0406DVD.ISO / Essentials / Programming / Basic4GL / Setup Basic4GL v2.3.3.exe / $INSTDIR / Programs / StickDude.gb < prev    next >
Encoding:
Text File  |  2005-10-05  |  2.7 KB  |  115 lines

  1. TextMode (TEXT_BUFFERED)
  2. locate 0, 3
  3. printr "              !Stick Dude!"
  4. printr
  5. printr "      Use arrow keys and space bar"
  6.  
  7. ' Load in all image frames
  8. dim allImages(ImageStripFrames("data\StickDude.png") - 1)
  9. allImages = LoadImageStrip("data\StickDude.png")
  10.  
  11. ' Split up frames into separate animations
  12. dim standImage, jumpImage, walkAnim(3), climpAnim(3)
  13.  
  14. ' Frame 0 is standing still
  15. standImage      = allImages(0)
  16.  
  17. ' Frames 1-4 are walking (right)
  18. walkAnim(0)     = allImages(1)
  19. walkAnim(1)     = allImages(2)
  20. walkAnim(2)     = allImages(3)
  21. walkAnim(3)     = allImages(4)
  22.  
  23. ' Frame 5 is jumping
  24. jumpImage       = allImages(5)
  25.  
  26. ' Frames 6-9 are climbing (up)
  27. climpAnim(0)    = allImages(6)
  28. climpAnim(1)    = allImages(7)
  29. climpAnim(2)    = allImages(8)
  30. climpAnim(3)    = allImages(9)
  31.  
  32. ' Display animation frames
  33. dim i
  34. for i = 0 to 9
  35.     NewSprite(allImages(i))
  36.     SprSetPos(i * 64 + 32, 448)
  37.     locate i * 4 + 1, 22: print i
  38. next
  39.                                         
  40. ' Create the sprite
  41. dim sprite
  42. Sprite = NewSprite(standImage)
  43. SprSetPos(320, 240)
  44.  
  45. ' Main animation loop
  46. while true
  47.  
  48.     ' Set the sprite animation and direction based on the
  49.     ' key being pressed
  50.     if ScanKeyDown(VK_SPACE) then
  51.     
  52.         ' Display jump image
  53.         SprSetTexture(jumpImage)
  54.  
  55.     elseif ScanKeyDown(VK_LEFT) then
  56.     
  57.         ' Display walk animation
  58.         SprSetTextures(walkAnim)
  59.         SprSetAnimSpeed(.2)
  60.         
  61.         ' Flip it so it faces left
  62.         SprSetXFlip(true)
  63.         
  64.         ' Move sprite left
  65.         SprSetVel(-1, 0)  
  66.  
  67.     elseif ScanKeyDown(VK_RIGHT) then
  68.     
  69.         ' Display walk animation
  70.         SprSetTextures(walkAnim)
  71.         SprSetAnimSpeed(.2)
  72.         
  73.         ' Unflipped, so it faces right
  74.         SprSetXFlip(false)
  75.         
  76.         ' Move sprite right    
  77.         SprSetVel(1, 0)    
  78.  
  79.     elseif ScanKeyDown(VK_UP) then
  80.     
  81.         ' Display climp animation
  82.         SprSetTextures(climpAnim)
  83.         SprSetAnimSpeed(.2)
  84.         
  85.         ' Move sprite up
  86.         SprSetVel(0, -2)
  87.  
  88.     elseif ScanKeyDown(VK_DOWN) then
  89.     
  90.         ' Display climb animation, going backwards
  91.         SprSetTextures(climpAnim)
  92.         SprSetAnimSpeed(-.2)
  93.         
  94.         ' Move sprite down
  95.         SprSetVel(0, 2)   
  96.  
  97.     else
  98.         
  99.         ' Display standing image
  100.         SprSetTexture(standImage)
  101.         
  102.         ' Stop sprite
  103.         SprSetVel(0, 0)
  104.  
  105.     endif    
  106.     
  107.     ' AnimateSprites automatically animates and moves all sprites
  108.     AnimateSprites()
  109.     
  110.     ' DrawText draws the sprites to screen
  111.     DrawText()
  112.     
  113.     ' WaitTimer slows down the main loop so things don't happen too fast
  114.     WaitTimer(20)
  115. wend